package com.lagou.edu.controller;

import com.lagou.edu.dao.ResumeDao;
import com.lagou.edu.pojo.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ResumeController {

    @Autowired
    private ResumeDao resumeDao;

    @RequestMapping("query")
    public ModelAndView query() {
        ModelAndView mv = new ModelAndView("resume.jsp");
        mv.addObject("list", resumeDao.findAll());
        return mv;
    }

    @RequestMapping("save")
    public ModelAndView save(Resume resume) {
        if(resume.getId() == 0) {
            resume.setId(null);
        }
        resumeDao.save(resume);
        return query();
    }

    @RequestMapping("delete")
    public ModelAndView remove(Long id) {
        resumeDao.deleteById(id);
        return query();
    }
}
